package com.lagou.rabbitmq.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName RabbitConfig
 * @Description
 * @Author playboy
 * @Date 2021/8/28 7:46 下午
 * @Version 1.0
 **/
@Configuration
public class RabbitConfig {
	private static Logger log = LoggerFactory.getLogger(RabbitConfig.class);

	@Bean
	public Queue queueTtl(){
		Queue queue = QueueBuilder.durable("queue.pay.ttl")
				.ttl(10*1000)
				.deadLetterExchange("ex.pay.dlx")
				.deadLetterRoutingKey("pay.dlx")
				.build();
		return queue;
	}

	@Bean
	public Queue queueDlx(){
		Queue queue = QueueBuilder.durable("queue.pay.dlx")
				.build();
		return queue;
	}

	@Bean
	public Exchange exchangeTtl(){
		Exchange exchange = ExchangeBuilder.topicExchange("ex.pay.ttl")
				.durable(true)
				.build();
		return exchange;
	}

	@Bean
	public Exchange exchangeDlx(){
		Exchange exchange = ExchangeBuilder.topicExchange("ex.pay.dlx")
				.durable(true)
				.build();
		return exchange;
	}

	@Bean
	public Binding bindingTtl(){
		Binding binding = BindingBuilder.bind(queueTtl()).to(exchangeTtl()).with("order").noargs();
		return binding;
	}

	@Bean
	public Binding bindingDlx(){
		Binding binding = BindingBuilder.bind(queueDlx()).to(exchangeDlx()).with("pay.dlx").noargs();
		return binding;
	}






}
